home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 5665 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.8 KB

  1. Path: nntp.teleport.com!usenet
  2. From: Jeff Grossman <grossman@teleport.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Structure member offsets at compile time - help!
  5. Date: 6 Feb 1996 06:02:13 GMT
  6. Organization: Teleport - Portland's Public Access (503) 220-1016
  7. Message-ID: <4f6qt5$d16@maureen.teleport.com>
  8. NNTP-Posting-Host: ip-pdx16-19.teleport.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.2N (Windows; I; 16bit)
  13.  
  14. I'm looking for a way to get an int offset to a structure member
  15. at compile time.
  16.  
  17. The reason is that I need to build a table of addresses of structure
  18. members (if you must know, its for simplifying the process of doing
  19. hundreds of ODBC SQLBindCol calls).
  20.  
  21. Right now I can create a table with addresses that point to a structure
  22. on the stack. I cannot use a static structure or a heap structure
  23. for these reasons:
  24.  
  25. 1) if the structure is static, it is not thread safe. If I protect
  26. it with a critical section, it introduces too much serialization into
  27. the application
  28.  
  29. 3) if the structure is on the heap, there is no way to create a compile
  30. time table (if I could figure that one out, I wouldn't need to post
  31. this question <g>! )
  32.  
  33. The drawback to the existing method is the huge amount of code generated
  34. to fill this structure at each procedure entry, If I had a compile
  35. time static structure with int offsets, I could add in the actual
  36. structure address as I needed.
  37.  
  38. Unfortunately, nothing I've tried works. I even tried a kludges such as:
  39.  
  40. (char)(&Struc.item) - (char)(&Struc)
  41.  
  42. This gives me int offsets. However, the compiler is not smart enough
  43. (even with optimization) to figure out that this is a compile time
  44. constant and generates code to do the pointer arithmetic.
  45.  
  46. Does anyone know a trick to get compile time structure offsets?
  47.  
  48. TIA.
  49.  
  50. Jeff
  51.  
  52.  
  53.